package com.yl.androidutilscenter.utils.ext

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2

/**
 * @author
 * @description:
 * @date :2024/5/10
 * @version 1.0.0
 */


/**
 * viewpager2 去除滑动顶部和底部时 继续滑动的水波纹
 */
fun ViewPager2.setOverScrollModeExt(overScrollMode: Int) {
    val view = getChildAt(0)
    if (view is RecyclerView) {
        view.overScrollMode = overScrollMode
    }
}

/**
 * viewpager2去掉边界滑动阴影效果
 * 使用反射
 */
fun ViewPager2.recyclerViewSetOverScrollMode() {
    try {
        val mRecyclerView = this.javaClass.getDeclaredField("mRecyclerView")
        mRecyclerView.isAccessible = true
        val recyclerView = mRecyclerView.get(this) as RecyclerView
        recyclerView.overScrollMode = View.OVER_SCROLL_NEVER
    }catch (e:Exception){
        e.printStackTrace()
    }

}